/**
 * Created by zander on 2017/12/9.
 */

/**
 * Created by zander on 2017/12/6.
 */
function getauthType1() {
    var select = document.getElementById("select1");
    var str = select.options[select.selectedIndex].value;
    return str
}

function getauthType2() {
    var select = document.getElementById("select2");
    var str = select.options[select.selectedIndex].value;
    return str
}

function selectPD() {
    var obj = getProject();
    if (obj == "jk") {
        $("#1").attr("class", "hidden");
        $("#2").attr("class", "show");
    } else if (obj == "zed") {
        $("#2").attr("class", "hidden");
        $("#1").attr("class", "show");
    } else if (obj == "sudi") {
        $("#1").attr("class", "hidden");
        $("#2").attr("class", "show");
    } else if (obj == "in") {
        $("#1").attr("class", "hidden");
        $("#2").attr("class", "show");
    } else {
        return false;
    }
}
function getProject() {
    var a = document.getElementById("Project");
    var b = a.options[a.selectedIndex].value;
    return b;
}

function clearInfo() {
    var patrn1 = /^[0-9]*[1-9][0-9]*$/;  //只能输入数字
    var patrn = /^[0-9a-zA-Z]/;//只能输入数字／字母a-z／字母A-Z
    var sta;
    var authType;
    var project = getProject();
    if (project == "jk") {
        sta = "-1";
        authType = getauthType2()
    } else if (project == "zed") {
        sta = "fail";
        authType = getauthType1()
    } else if (project == "sudi") {
        sta = "-1";
        authType = getauthType2()
    } else if (project == "in") {
        sta = "-1";
        authType = getauthType2()
    }
    var phone = document.getElementById('inputPhone').value;
    var identifier = document.getElementById('inputID').value;
    if (phone == "") {
        alert("手机号为空");
        return false;
    } else if (identifier == "") {
        alert("身份证号为空");
        return false;
    } else if (project == "") {
        alert("授信项目为空");
        return false;
    } else if (!patrn1.test(phone)) {
        alert("手机号只能输入数字");
        return false;
    } else if (!patrn.test(identifier)) {
        alert("身份证号格式不正确");
        return false;
    }
    document.getElementById('res').innerText = '';
    sure(project, authType, phone, identifier,sta)
}

function sure(project, authType, phone, identifier, sta) {
    bootbox.confirm({
        size: "small",
        message: "是否确认执行?",
        callback: function (result) {
            if (result == true) {
                $.ajax({
                    type: "POST",
                    url: "/intest/v1/rd/modifyC2auth",
                    data: {
                        phone: phone,
                        identifier: identifier,
                        project: project,
                        item: authType,
                        status: sta
                    },
                    dataType: "json",
                    beforeSend: function () {
                        $("body").mLoading("show");
                    },
                    success: function (ret) {
                        if (ret.status == "0000") {
                            $("body").mLoading("hide");
                            $("#res").append(ret.content);
                        } else {
                            $("body").mLoading("hide");
                            $("#res").append(ret.content);
                        }
                    },
                    error: function() {
                        $("body").mLoading("hide");
                        $("#res").append("Error 500,请联系开发人员！");
                    }
                });

            }
        }
    })
}

